/**
* enterGroupStatsChart functions
* copyright@Catosoft.com reserved, 2016
* 2016.07.30, created by Eric.Wang
*/



/*
* get data
*/
var getEnterGroupStatsData = function(){
	var data = {

	};
	var option = {
		url: '/draft/group/in/stats/v1',
		type: 'GET',
		data: data,
	};
	createAjax(option, function(err, res){
		if(!err){
			enterGroupStatsTable('enterGroupStatsTable', res);
		}
	});
}

/*
* data filter
*/
var enterGroupStatsTableFilter = function(data){
	var done = 0;
	var not = 0;
	$.each(data.list, function(index, item){
		if(item.status == '入组'){
			done += item.person_num;
		}else if(item.status == '筛选失败'){
			not += item.person_num;
		}
	});
	data.list = data.list.concat([{
		pursuercodes: '完成',
		person_num: done,
	}, {
		pursuercodes: '未完成',
		person_num: not,
	}, {
		pursuercodes: '完成率',
		person_num: (done / (done + not) * 100).toFixed(3) + '%',
	}]);
}

/*
* draw charts
*/
var enterGroupStatsTable = function(element, data){
	enterGroupStatsTableFilter(data);
	$('#' + element).bootstrapTable({
		data: data.list,
		classes: 'table table-hover',
		pagination: false,
		pageSize: 20,
		pageNumber: 1,
		pageList: [20, 50],
		sidePagination: 'client',
		showRefresh: true,
		showColumns: true,
		buttonsAlign: 'right',
		showExport: true,
		exportDataType: 'all',
		exportTypes: ['csv', 'txt', 'excel'],
		locale: 'zh-CN',
		columns: [
		{
			field: 'Number',  
	    title: '序号',  
	    formatter: function (value, row, index) {  
	    	return index + 1;  
	    }
		},
		{
			title: '中心',
			field: 'pursuercodes',
		}, {
			title: '状态',
			field: 'status',
		}, {
			title: '受试者数量',
			field: 'person_num',
		}],

	});
}

$(function(){
	getEnterGroupStatsData();
});
